package com.zhou.common.mybatis.template.shiro.util;

import feign.Contract;
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author li.ke
 * @date 2022/3/9
 */
@Configuration
public class FlowClientFeignConfiguration {
    @Bean
    public Logger.Level flowLoggerLevel() {
        return Logger.Level.FULL;
    }

    /*@Bean
    public WebMvcRegistrations feignWebRegistrations() {
        return new WebMvcRegistrations() {
            @Override
            public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
                return new FeignRequestMappingHandlerMapping();
            }
        };
    }

    */

    /**
     * swagger过滤同时被 @FeignClient和@RequestMapping 修饰的类
     *//*
    private static class FeignRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
        @Override
        protected boolean isHandler(Class<?> beanType) {
            return super.isHandler(beanType) &&
                    !AnnotatedElementUtils.hasAnnotation(beanType, FeignClient.class);
        }
    }*/

    //SpringMvcContract
    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
    }


//    @Component
//    public class DemoWebMvcRegistrations implements WebMvcRegistrations {
//        @Override
//        public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
//            return new DemoRequestMappingHandlerMapping();
//        }
//
//    }
//
//    /**
//     * 注意这个地方不能直接将bean 直接注入到spring 环境，
//     * 否则你会发现里面每一个controller 都会被映射2次
//     *
//     * @see org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.MappingRegistry#getMappingsByUrl
//     **/
//    public class DemoRequestMappingHandlerMapping extends RequestMappingHandlerMapping implements WebMvcRegistrations {
//        @Override
//        protected boolean isHandler(Class<?> beanType) {
//            return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) ||
//                    // 当前类上存在RequestMapping 但是不存在FeignClient注解
//                    (AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class)
//                            && !AnnotatedElementUtils.hasAnnotation(beanType, FeignClient.class)
//                    ));
//        }
//    }

}
